﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Model;
using Besture.Bll;
using System.Data;
using Besture.Common.Definition;

namespace Besture.UI.Education
{
    public partial class Education : System.Web.UI.Page
    {
        //Banner图
        public ImageModel _BannerTop { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
            GetBanner();
        }

        #region 初始化数据
        private void InitData()
        {
            ActiveNewsClassDac dac = new ActiveNewsClassDac();
            DataTable dt = dac.GetDataTable(Constants.DICTIONARY_Code_NewsClassEd);
            rbMeList.DataSource = dt;
            rbMeList.DataBind();

            rbMeTypeList.DataSource = dt;
            rbMeTypeList.DataBind();
        }
        #endregion

        #region Repeater绑定事件
        /// <summary>
        /// 绑定套餐下的商品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rbMeTypeList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rp = e.Item.FindControl("rbMeDeList") as Repeater;
            Repeater rptop = e.Item.FindControl("rbMeDeTopList") as Repeater;
            int id = Convert.ToInt32((e.Item.DataItem as DataRowView)["ID"]);
            DataTable dt = new ActiveNewsDac().GetDataTableByClassID(id);
            DataTable fid = new DataTable();
            DataTable topfid = new DataTable();
            fid = dt.Clone();
            topfid = dt.Clone();
            if (dt != null && dt.Rows.Count > 0)
            {
                int i=0;
                foreach (DataRow dr in dt.Rows)
                {
                    if (i==0)
                    {
                        topfid.ImportRow(dr);
                    }
                    else if(fid.Rows.Count<5)
                    {
                        fid.ImportRow(dr);
                    }
                    i++;
                }
            }
            rp.DataSource = fid;
            rp.DataBind();

            rptop.DataSource = topfid;
            rptop.DataBind();
        }
        #endregion

        #region 获取Banner
        /// <summary>
        /// 获取Banner
        /// </summary>
        public void GetBanner()
        {
            ImageDac imageDac = new ImageDac();
            ImageModel imgModel = imageDac.GetDataTableByCode(Constants.DICTIONARY_CODE_BannerEducation, Constants.DICTIONARY_TYPE_IMAGES);
            if (imgModel != null)
                _BannerTop = imgModel;
            else
                _BannerTop = new ImageModel();
        }
        #endregion
    }
}